Rob J Hyndman
Padova: 23 September 2022
Available cyclic granularities for half-hourly data:
[1] "hhour_hour" "hhour_day" "hhour_week"
[4] "hhour_fortnight" "hhour_month" "hhour_quarter"
[7] "hhour_semester" "hhour_year" "hour_day"
[10] "hour_week" "hour_fortnight" "hour_month"
[13] "hour_quarter" "hour_semester" "hour_year"
[16] "day_week" "day_fortnight" "day_month"
[19] "day_quarter" "day_semester" "day_year"
[22] "week_fortnight" "week_month" "week_quarter"
[25] "week_semester" "week_year" "fortnight_month"
[28] "fortnight_quarter" "fortnight_semester" "fortnight_year"
[31] "month_quarter" "month_semester" "month_year"
[34] "quarter_semester" "quarter_year" "semester_year"
Plot options:
day_year \times month_yearharmonies <- vic_elec |>
harmony(filter_out = c("hour","fortnight","quarter","semester"))
vic_elec |>
rank_harmonies(harmonies, response = Demand) |>
filter(facet_levels < 20)# A tibble: 10 × 5
facet_variable x_variable facet_levels x_levels wpd
<chr> <chr> <int> <int> <dbl>
1 month_year hhour_day 12 48 124.
2 day_week hhour_day 7 48 76.6
3 month_year day_week 12 7 63.3
4 month_year week_month 12 5 59.7
5 week_month month_year 5 12 55.9
6 week_month hhour_day 5 48 51.5
7 week_month day_week 5 7 47.4
8 day_week day_month 7 31 44.1
9 day_week month_year 7 12 37.7
10 day_week week_month 7 5 23.9
forecast and fable.y_t = T_t + \sum_{i=1}^I S_t^{(i)} + R_t
| y_t= | observation at time t |
| T_t= | smooth trend component |
| S_t^{(i)}= | seasonal component i |
| i = 1,\dots,I | |
| R_t= | remainder component |
Estimation
Components updated iteratively.
# X: time series object
# periods: vector of seasonal periods in increasing order
# s.window: seasonal window values
# iterate: number of STL iterations
seasonality <- matrix(0, nrow = nrow(X), ncol = length(periods))
deseas <- X
for (j in 1:iterate) {
for (i in 1:length(periods)) {
deseas <- deseas + seasonality[, i]
fit <- model(
STL(deseas ~ season(period = periods[i], window = s.window[i]))
) |>
components()
seasonality[, i] <- fit$season
deseas <- deseas - seasonality[, i]
}
}
trend <- fit$trend
remainder <- deseas - trend
return(trend, remainder, seasonality)
Alex Dokumentov and Rob J Hyndman (2022) STR: Seasonal-Trend decomposition using Regression. INFORMS Journal on Data Science, to appear. robjhyndman.com/publications/str/
Implemented in R package stR.
y_{t} = T_{t} + \sum_{i=1}^{I} S^{(i)}_{t} + \sum_{p=1}^P \phi_{p,t} z_{t,p} + R_{t}
| T_t= | smooth trend component |
| S_t^{(i)}= | seasonal component i (possibly complex topology) |
| z_{p,t}= | covariate with coefficient \phi_{p,t} (possibly time-varying) |
| R_t= | remainder component |
Estimation
Components estimated using penalized MLE
Smooth trend obtained by requiring \Delta_2 T_t \sim \text{NID}(0,\sigma_L^2)
f(\bm{D}_\ell \bm{\ell}) \propto \exp\left\{-\frac{1}{2}\big\|\bm{D}_\ell \bm{\ell} / \sigma_L\big\|_{L_2}^2\right\}
Smoothness in time t direction:
\begin{align*} \bm{D}_{tt,i} \bm{s}_i &= \langle \Delta^2_{t} \bm{S}^{(i)}_{k,t} \rangle \sim \text{NID}(\bm{0},\sigma_{i}^2 \bm{\Sigma}_{i})\\ f(\bm{s}_i) &\propto \exp\Big\{-\frac{1}{2}\big\|\ \bm{D}_{tt,i}\bm{s}_i / \sigma_i\big\|_{L_2}^2\Big\} \end{align*}
Analogous difference matrices \bm{D}_{kk,i} and \bm{D}_{kt,i} ensure smoothness in season and time-season directions.
Minimize wrt \bm{\Phi}, \bm{\ell} and \bm{s}_i:
\begin{align*} -\log \mathcal{L} &= \frac{1}{2\sigma_R} \Bigg\{ \Big\| \bm{y}- \sum_{i=1}^I \bm{Q}_i\bm{s}_i - \bm{\ell} - \bm{Z}\bm{\Phi} \Big\|_{L_2}^2 + \lambda_\ell\Big\|\bm{D}_\ell \bm{\ell}\Big\|_{L_2}^2 \\ & \hspace*{1cm} + \sum_{i=1}^{I}\left( \left\|\lambda_{tt,i} \bm{D}_{tt,i} \bm{s}_i \right\|_{L_2}^2 + \left\|\lambda_{st,i} \bm{D}_{st,i} \bm{s}_i \right\|_{L_2}^2 + \left\|\lambda_{ss,i} \bm{D}_{ss,i} \bm{s}_i \right\|_{L_2}^2 \right) \Bigg\} \end{align*}
\bm{y}_{+} = \bm{X}\bm{\beta} + \bm{\varepsilon}
\bm{X} = \begin{bmatrix} \bm{Q}_1 & \dots & \bm{Q}_I & \bm{I}_n & \bm{Z} \\ \lambda_{tt,1} \bm{D}_{tt,1} & \dots & 0 & 0 & 0 \\ \lambda_{st,1} \bm{D}_{st,1} & \dots & 0 & 0 & 0 \\ \lambda_{ss,1} \bm{D}_{ss,1} & \dots & 0 & 0 & 0 \\ 0 & \ddots & 0 & 0 & 0 \\ 0 & \dots & \lambda_{tt,I} \bm{D}_{tt,I} & 0 & 0 \\ 0 & \dots & \lambda_{st,I} \bm{D}_{st,I} & 0 & 0 \\ 0 & \dots & \lambda_{ss,I} \bm{D}_{ss,I} & 0 & 0 \\ 0 & \dots & 0 & \lambda_\ell \bm{D}_{tt} & 0 \end{bmatrix}
Three seasonal components, quadratic temperature regressors
Slides: robjhyndman.com/seminars/padova2022